import 'package:common_utils/common_utils.dart';

class TimeUtil {
  static String formatTime(String time) {
    var str =
        DateTime.fromMillisecondsSinceEpoch(int.parse(time)); //将拿到的时间戳转化为日期
    DateTime dateTime = DateTime.now();
    var year = dateTime.year.toString();
    var t = str.toLocal().toString();
    var y = t.substring(0, 4);
    if (year == y) {
      return t.substring(5, 10);
    } else {
      return t.substring(0, 10);
    }
  }

  static String formatDate(String time) {
    var str = DateUtil.formatDateStr(time, format: "yyyy-MM-dd");
    DateTime dateTime = DateTime.now();
    var year = dateTime.year.toString();
    var t = str.toString();
    var y = t.substring(0, 4);
    if (year == y) {
      return t.substring(5, 10);
    } else {
      return t.substring(0, 10);
    }
  }
}
